package usernew;

import com.sun.org.apache.bcel.internal.generic.NEW;
import java.util.HashMap;
import java.util.Iterator;
import sun.awt.SunHints.Value;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 8:59
 * @description:
 */
public class Userdaomap implements  Userdao {

  HashMap<String,User> map=new HashMap<String,User>();


  @Override
  public void zhuce(User user) {
    map.put(user.getName(),user);

  }

  @Override
  public boolean login(String name, String password) {

    Iterator iterator=map.keySet().iterator();
    while (iterator.hasNext())
    {
      String key=(String )iterator.next();
      User value=map.get(key);
    //  比较
      if(name.equals(key)&& password.equals(value.getPassword()))
      {
        return  true;
      }
    }


    return  false;
  }

  @Override
  public void chaall() {

    System.out.println("所有用户如下");
    Iterator iterator = map.keySet().iterator();
    while (iterator.hasNext()) {

      String key = (String) iterator.next();
      User value = map.get(key);
      System.out.println(key + value);

    }
  }

  @Override
  public void shanchu(String name, String password) {

    if(map.containsKey(name))
    {
      map.remove(name);
      map.remove(map.get(name));
    }

  }

  @Override
  public void shanchu(String name) {

  }


}